<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1" />
		<title>蒙层与弹窗</title>
		<style type="text/css">
			* {
				margin: 0;
				padding: 0;
			}
			#mask {
				position: fixed;
				top: 0;
				bottom: 0;
				left: 0;
				right: 0;
				background: rgba(0, 0, 0, 0.3);
				z-index: 1000;
			}
			#btn {
				display: block;
				margin: 0 auto;
			}
			.hide {
				display: none !important;
			}
			.long-content > div {
				width: fit-content;
				height: 300px;
				margin: 0 auto;
			}
			#pop-window {
				width: 300px;
				height: 100px;
				z-index: 1001;
				background: #fff;
				display: flex;
				align-items: center;
				justify-content: center;
			}

			.pop-window-center {
				position: fixed;
				top: 50%;
				left: 50%;
				transform: translate(-50%, -50%);
			}
		</style>
	</head>
	<body>
		<div class="long-content">
			<div>long content</div>
			<div>long content</div>
			<div>long content</div>
			<button id="btn">点击出现弹窗</button>
			<div>long content</div>
			<div>long content</div>
			<div>long content</div>
			<div>long content</div>
		</div>
		<div id="mask" class="hide"></div>
		<div id="pop-window" class="hide pop-window-center">
			<div>pop-window-content</div>
		</div>
	</body>
	<script type="text/javascript">
		const btn = document.getElementById("btn");
		const mask = document.getElementById("mask");
		const popwindow = document.getElementById("pop-window");
		btn.addEventListener("click", (e) => {
			mask.classList.remove("hide");
			popwindow.classList.remove("hide");
		});

		mask.addEventListener("click", (e) => {
			mask.classList.add("hide");
			popwindow.classList.add("hide");
		});

		popwindow.addEventListener("click", (e) => {
			mask.classList.add("hide");
			popwindow.classList.add("hide");
		});
	</script>
</html>
